package com.woniuxy.rms.service.impl;

import com.woniuxy.rms.dao.OrdersMapper;
import com.woniuxy.rms.dao.ServerOrdersMapper;
import com.woniuxy.rms.dto.OrderDTO;
import com.woniuxy.rms.service.DealService;
import com.woniuxy.rms.util.DataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Auther: ChenGang  <br/>
 * Date: 2020/3/28 0028:下午 1:28  <br/>
 * Description:交易服务层
 */
@Service
public class DealServiceImpl implements DealService {

    @Autowired
    OrdersMapper ordersMapper;

    @Autowired
    ServerOrdersMapper serverOrdersMapper;

    @Override
    public List<OrderDTO> findGoodsByPage(Integer currentPage, Integer pageSize,Integer status) {
        return ordersMapper.findByPage(currentPage,pageSize,status);
    }

    @Override
    public DataResult checkGoodsOrder(String ids, Integer status) {
        if (status == null){
            return DataResult.failed("请选择订单状态");
        }
        ordersMapper.checkOrder(Arrays.stream(ids.split(",")).map(s -> Long.parseLong(s)).collect(Collectors.toList()),status,new Date());
        return DataResult.success();
    }

    @Override
    public List<OrderDTO> findServerByPage(Integer currentPage, Integer pageSize, Integer status) {
        return serverOrdersMapper.findByPage(currentPage,pageSize,status);
    }

    @Override
    public DataResult checkServerOrder(String ids, Integer payStatus) {
        if (payStatus == null){
            return DataResult.failed("请选择订单状态");
        }
        serverOrdersMapper.checkOrder(Arrays.stream(ids.split(",")).map(s -> Long.parseLong(s)).collect(Collectors.toList()),payStatus,new Date());
        return DataResult.success();
    }
}